﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Employee_ChangeStatusVacancy : System.Web.UI.Page
{
    string VacancyID = "";
    string UserName = "";
    EmployeeMethord EM = new EmployeeMethord();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            txtDateFilfilled_CalendarExtender.StartDate = DateTime.Now;
            VacancyID = Request.QueryString["ID"].ToString();
            if (ddlTitle.Text.Equals(""))
            {
                if (!IsPostBack)
                {
                    LoadInformationVacancy(VacancyID);
                }
            }
            btnSave.Enabled = false;
        }
        catch (Exception ex)
        {
        }
    }    

    private void LoadInformationVacancy(string _VacancyID)
    {
        DataTable tb = EM.ReturnInformationVacancy(_VacancyID, UserName);
        if (tb.Rows.Count > 0)
        {
            ddlTitle.Items.Add(tb.Rows[0]["Title"].ToString());
            txtVacancyID.Text = tb.Rows[0]["VacancyID"].ToString();
            txtDecription.Text = tb.Rows[0]["Description"].ToString();
            txtNumberofJob.Text = tb.Rows[0]["NumberOfJob"].ToString();
            txtSalary.Text = tb.Rows[0]["Salary"].ToString();
            txtAddress.Text = tb.Rows[0]["Workplace"].ToString();
            txtDateCreation.Text = tb.Rows[0]["DateCreatioin"].ToString();
            txtDateFilfilled.Text = tb.Rows[0]["DateFulfilled"].ToString();

            switch (Convert.ToInt32(tb.Rows[0]["Status"].ToString()))
            {
                case 1:
                    ddlStatus.SelectedIndex = 0;
                    break;
                case 2:
                    ddlStatus.SelectedIndex = 1;
                    break;
                case 3:
                    ddlStatus.SelectedIndex = 2;
                    break;
            }
        }
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        lblSuccess.Text = "";
        lblError.Text = "";
        bool check = EM.UpdateStatusVacancy(txtVacancyID.Text, Convert.ToInt32(ddlStatus.SelectedItem.Value));
        if (check)
        {
            lblSuccess.Text = "Changed the status of VancancyID to " + ddlStatus.SelectedItem.Text;
        }
        else
        {
            lblError.Text = "Changes process failure status";
        }
    }
}